package com.finfosoft.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.finfosoft.bean.Person;
import com.finfosoft.service.PersonService;

@RestController
public class PersonController {

	@Autowired
	PersonService personService;

	@RequestMapping("/put")
	public Person put(Person person) {
		Person p = personService.save(person);
		return p;
	}

	@RequestMapping("/evit")
	public String evit(long id) {
		personService.remove(id);
		return "ok";
	}

	@RequestMapping("/able")
	public Person cacheable(Person p) {
		Person person = personService.findOne(p);
		return person;
	}

	
	@RequestMapping("/save")
	public Person savePerson(Person p) {
		p.setName("xiaogou");
		p.setAge(1);
		Person person = personService.savePersonWithRollBack(p);
		return person;
	}
	
	@RequestMapping("/save2")
	public Person savePerson2(Person p) {
		p.setName("xiaogou");
		p.setAge(1);
		Person person = personService.savePersonWithnoRollbackFor(p);
		return person;
	}
}
